home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / mempools.lha / mempools / calloc.c next >
Encoding:
C/C++ Source or Header  |  1994-12-05  |  1.7 KB  |  75 lines

  1. /**
  2. ***  MemPools:    malloc() replacement using standard Amiga pool functions.
  3. ***  Copyright    (C)  1994    Jochen Wiedmann
  4. ***
  5. ***  This program is free software; you can redistribute it and/or modify
  6. ***  it under the terms of the GNU General Public License as published by
  7. ***  the Free Software Foundation; either version 2 of the License, or
  8. ***  (at your option) any later version.
  9. ***
  10. ***  This program is distributed in the hope that it will be useful,
  11. ***  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ***  GNU General Public License for more details.
  14. ***
  15. ***  You should have received a copy of the GNU General Public License
  16. ***  along with this program; if not, write to the Free Software
  17. ***  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ***
  19. ***
  20. ***  This file contains the calloc() replacement.
  21. ***
  22. ***
  23. ***  Computer:    Amiga 1200
  24. ***
  25. ***  Compilers: Dice 3.01
  26. ***        SAS/C 6.3
  27. ***        gcc 2.6.1
  28. ***
  29. ***
  30. ***  Author:    Jochen Wiedmann
  31. ***        Am Eisteich 9
  32. ***      72555 Metzingen
  33. ***        Germany
  34. ***
  35. ***        Phone: (0049) 7123 14881
  36. ***        Internet: jochen.wiedmann@uni-tuebingen.de
  37. **/
  38.  
  39.  
  40.  
  41.  
  42. /*
  43.     Include files and compiler specific stuff
  44. */
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <errno.h>
  48. #include <exec/types.h>
  49. #include <clib/alib_protos.h>
  50.  
  51.  
  52.  
  53.  
  54. extern APTR __MemPool;
  55.  
  56.  
  57.  
  58.  
  59. #define sptr ((size_t *) ptr)
  60. void *calloc(size_t size, size_t numobjs)
  61.  
  62. { void *ptr;
  63.  
  64.   if ((size *= numobjs))
  65.   { if ((ptr = LibAllocPooled(__MemPool, size+sizeof(size_t))))
  66.     { sptr[0] = size;
  67.       ptr = &sptr[1];
  68.       memset(ptr, '\0', size);
  69.       return(ptr);
  70.     }
  71.     errno = ENOMEM;
  72.   }
  73.   return(NULL);
  74. }
  75.